import Vue from 'vue';
import Router from 'vue-router';

// 按需（懒）加载（vue实现）      @ is an alias to /src
const Layout = () => import('@/views/layouts/layout.vue');// 布局组件
const Login = () => import('@/views/auth/index.vue');// 登录
const Main = () => import('@/views/index/index.vue');// 首页

//用户部分
const Manager = () => import('@/views/user/manager.vue');// 管理人员
const User = () => import('@/views/user/index.vue');// 会员管理
const Column = () => import('@/views/user/column.vue');// 专栏管理
const Integral = () => import('@/views/user/integral.vue');// 积分设置

//新闻管理
const New = () => import('@/views/new/index.vue');// 新闻列表
const NewColumn = () => import('@/views/new/column.vue');// 专栏新闻
const NewUpdate = () => import('@/views/new/update.vue');// 新闻更新
const NewCate = () => import('@/views/new/category.vue');// 新闻分类
const NewTag = () => import('@/views/new/tag.vue');// 新闻标签

//项目管理
const Project = () => import('@/views/project/index.vue');// 项目列表
const ProjectUpdate = () => import('@/views/project/update.vue');// 项目更新
const ProjectCate = () => import('@/views/project/category.vue');// 项目分类

//学院管理
const College = () => import('@/views/college/index.vue');// 学院列表
const CollegeUpdate = () => import('@/views/college/update.vue');// 学院更新
const CollegeCate = () => import('@/views/college/category.vue');// 学院分类

//单页应用
const Page = () => import('@/views/page/index.vue');// 单页列表
const PageUpdate = () => import('@/views/page/update.vue');// 单页更新

//快讯
const Live = () => import('@/views/new/live.vue');// 快讯列表

//系统设置
const Config = () => import('@/views/setting/config.vue');// 网站设置

//网站管理
const Chanel = () => import('@/views/setting/chanel.vue');// 导航管理
const Webseo = () => import('@/views/setting/seo.vue');// SEO设置
const Friend = () => import('@/views/setting/friend.vue');// 友情链接


const Error404 = () => import('@/views/page/404.vue');//404
Vue.use(Router);
//设置不需要权限的公共页面
//login 登录成功后不能在访问该页面
export const constantRouterMap= [
    {path: '/login', name: 'Login',component: Login, meta: {title: '登录', login:true}},
    {
        path: '/', component: Layout, redirect: '/main',
        children:[
            {path: '/main', name: 'Main', component: Main,meta: {title:'小程序库',show:true,'icon':'fa fa-home'}},
            {path: '/error/404', name: 'Error404', component: Error404, meta: {title:'404',show:false}},
        ],
    },
];
//实例化vue的时候只挂载constantRouter
export default new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: constantRouterMap
});
//异步挂载的路由
//动态需要根据权限加载的路由表
//access：权限ID，show：菜单是否展示，title:页面title,icon:菜单图标
export const asyncRouterMap = [
    {
        path: '/new',
        component: Layout,
        redirect: '/new',
        meta: {title:'新闻管理','icon':'fa fa-file-text'},
        children:[
            {path: '/new',          name: 'New',       component: New,       meta: {title:'新闻列表',show:true}},
            {path: '/new/column',   name: 'NewColumn', component: NewColumn, meta: {title:'专栏新闻',show:true}},
            {path: '/new/update',   name: 'NewUpdate', component: NewUpdate, meta: {title:'新闻更新',show:false}},
            {path: '/new/cate',     name: 'NewCate',   component: NewCate,   meta: {title:'新闻类目',show:true}},
            {path: '/new/tag',      name: 'NewTag',    component: NewTag,    meta: {title:'新闻标签',show:true}},
        ],
    },
    {
        path: '/live',
        component: Layout,
        redirect: '/live',
        meta: {title:'快讯管理','icon':'fa fa-align-justify'},
        children:[
            {path: '/live',          name: 'Live',       component: Live,       meta: {title:'快讯列表',show:true}},
        ],
    },
    {
        path: '/project',
        component: Layout,
        redirect: '/project',
        meta: {title:'项目管理','icon':'fa fa-product-hunt'},
        children:[
            {path: '/project',          name: 'Project',       component: Project,       meta: {title:'项目列表',show:true}},
            {path: '/project/update',   name: 'ProjectUpdate', component: ProjectUpdate, meta: {title:'项目更新',show:false}},
            {path: '/project/cate',     name: 'ProjectCate',   component: ProjectCate,   meta: {title:'项目类目',show:true}},
        ],
    },
    {
        path: '/college',
        component: Layout,
        redirect: '/college',
        meta: {title:'学院管理','icon':'fa fa-resistance'},
        children:[
            {path: '/college',          name: 'College',       component: College,       meta: {title:'学院列表',show:true}},
            {path: '/college/update',   name: 'CollegeUpdate', component: CollegeUpdate, meta: {title:'学院更新',show:false}},
            {path: '/college/cate',     name: 'CollegeCate',   component: CollegeCate,   meta: {title:'学院类目',show:true}},
        ],
    },
    {
        path: '/user',
        component: Layout,
        redirect: '/user',
        meta: {title:'用户管理','icon':'fa fa-user'},
        children:[
            {path: '/user',          name: 'User',       component: User,       meta: {title:'会员列表',show:true}},
            {path: '/column',        name: 'Column',     component: Column,     meta: {title:'专栏列表',show:true}},
            {path: '/integral',      name: 'Integral',   component: Integral,   meta: {title:'积分设置',show:true}},
        ],
    },
    {
        path: '/chanel',
        component: Layout,
        redirect: '/chanel',
        meta: {title:'网站管理','icon':'fa fa-windows'},
        children:[
            {path: '/chanel',           name: 'Chanel',     component: Chanel,     meta: {title:'导航设置',show:true}},
            {path: '/webseo',           name: 'Webseo',     component: Webseo,     meta: {title:'SEO设置',show:true}},
            {path: '/friend',           name: 'Friend',     component: Friend,     meta: {title:'友情链接',show:true}},
            {path: '/page',             name: 'Page',       component: Page,       meta: {title:'单页应用',show:true}},
            {path: '/page/update',      name: 'PageUpdate', component: PageUpdate, meta: {title:'单页更新',show:false}},
        ],
    },
    {
        path: '/config',
        component: Layout,
        redirect: '/config',
        meta: {title:'系统配置','icon':'fa fa-cog'},
        children:[
            {path: '/config',           name: 'Config',     component: Config,     meta: {title:'网站设置',show:true}},
            {path: '/manager',          name: 'Manager',    component: Manager,    meta: {title:'管理人员',show:true}},
        ],
    },
    { path: '*',redirect: '/error/404',meta: {show:false},}
];
